﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ECommerce.WebControls
{
    public class ObjetoListItem : System.Web.UI.WebControls.CompositeControl
    {
        protected System.Web.UI.WebControls.CheckBox chkCheckBox = new System.Web.UI.WebControls.CheckBox();
        protected System.Web.UI.WebControls.HiddenField hdnValue = new System.Web.UI.WebControls.HiddenField();
        protected System.Web.UI.WebControls.Label lblText0 = new System.Web.UI.WebControls.Label();
        protected System.Web.UI.WebControls.Label lblText = new System.Web.UI.WebControls.Label();
        protected System.Web.UI.WebControls.Label lblText1 = new System.Web.UI.WebControls.Label();
        protected System.Web.UI.WebControls.Label lblText2 = new System.Web.UI.WebControls.Label();
        protected System.Web.UI.WebControls.LinkButton lnkAdd = new System.Web.UI.WebControls.LinkButton();
        protected System.Web.UI.WebControls.HyperLink lnkEdit = new System.Web.UI.WebControls.HyperLink();
        protected System.Web.UI.WebControls.LinkButton lnkDel = new System.Web.UI.WebControls.LinkButton();
        protected System.Web.UI.WebControls.ImageButton imgbtnDel = new System.Web.UI.WebControls.ImageButton();
        public event System.Web.UI.WebControls.CommandEventHandler lnkAddCommand;
        public event System.Web.UI.WebControls.CommandEventHandler lnkDelCommand;
        System.Web.UI.WebControls.Literal br = new System.Web.UI.WebControls.Literal();
        System.Web.UI.WebControls.Literal abreDiv = new System.Web.UI.WebControls.Literal();
        System.Web.UI.WebControls.Literal cierraDiv = new System.Web.UI.WebControls.Literal();
        protected override void CreateChildControls()
        {
            br.Text = "<br/>";
            abreDiv.Text = "<div class=\"" + this.CssClass.ToString() + "\">";
            cierraDiv.Text = "</div>";
            imgbtnDel.AlternateText = "Borrar";
            imgbtnDel.Attributes.Add("Title", "Borrar");
            base.CreateChildControls();
            if (this.CssClass!=null && this.CssClass!="")
                this.Controls.Add(abreDiv);
            this.Controls.Add(chkCheckBox);
            this.Controls.Add(hdnValue);
            lblText0.Style.Add("text-align", "center");
            this.Controls.Add(lblText0);
            lblText.Style.Add("text-align", "left");
            this.Controls.Add(lblText);
            lblText1.Style.Add("text-align", "right");
            this.Controls.Add(lblText1);
            lblText2.Style.Add("text-align", "right");
            this.Controls.Add(lblText2);
            this.Controls.Add(lnkAdd);
            this.Controls.Add(lnkEdit);
            this.Controls.Add(lnkDel);
            if (imgbtnDel.ImageUrl != null &&imgbtnDel.ImageUrl != "")
                this.Controls.Add(imgbtnDel);
            if (this.CssClass != null && this.CssClass != "")
                this.Controls.Add(cierraDiv);
        }
        public bool CheckBoxVisible
        {
            get { return chkCheckBox.Visible; }
            set { chkCheckBox.Visible = value; }
        }
        public bool Checked
        {
            get { return this.chkCheckBox.Checked; }
            set { this.chkCheckBox.Checked = value; }
        }
        public string Value
        {
            get { return this.hdnValue.Value; }
            set 
            {
                this.hdnValue.Value = value;
                this.lnkAdd.CommandArgument = value.ToString();
                this.lnkDel.CommandArgument = value.ToString();
                this.imgbtnDel.CommandArgument = value.ToString();
            }
        }
        public string Text0
        {
            get { return this.lblText0.Text; }
            set { this.lblText0.Text = value; }
        }
        public string Text
        {
            get { return this.lblText.Text; }
            set { this.lblText.Text = value; }
        }
        public string Text1
        {
            get { return this.lblText1.Text; }
            set { this.lblText1.Text = value; }
        }
        public string Text2
        {
            get { return this.lblText2.Text; }
            set { this.lblText2.Text = value; }
        }
        public string AttributtesTarget
        {
            set { this.lnkEdit.Attributes.Add("target",value); }
        }
        public System.Web.UI.WebControls.Unit Text0Size
        {
            get { return this.lblText0.Width; }
            set { this.lblText0.Width = value; }
        }
        public System.Web.UI.WebControls.Unit TextSize
        {
            get { return this.lblText.Width; }
            set { this.lblText.Width = value; }
        }
        public System.Web.UI.WebControls.Unit Text1Size
        {
            get { return this.lblText1.Width; }
            set { this.lblText1.Width = value; }
        }
        public System.Web.UI.WebControls.Unit Text2Size
        {
            get { return this.lblText2.Width; }
            set { this.lblText2.Width = value; }
        }
        public string AddText
        {
            get { return this.lnkAdd.Text; }
            set { this.lnkAdd.Text = value; }
        }
        public string EditText
        {
            get { return this.lnkEdit.Text; }
            set { this.lnkEdit.Text = value; }
        }
        public string EditNavigateUrl
        {
            get { return this.lnkEdit.NavigateUrl; }
            set { this.lnkEdit.NavigateUrl = value; }
        }
        public string DelText
        {
            get { return this.lnkDel.Text; }
            set { this.lnkDel.Text = value; }
        }
        public string DelImageUrl
        {
            get { return this.imgbtnDel.ImageUrl; }
            set { this.imgbtnDel.ImageUrl = value; }
        }
        public ObjetoListItem()
        { }
        public ObjetoListItem(bool Checked, string Value, string Text)
        {
            this.Checked = Checked;
            this.Value = Value;
            this.Text = Text;
        }
        public ObjetoListItem(bool Checked, string Value, string Text0, string Text, string Text1, string Text2)
        {
            this.Checked = Checked;
            this.Value = Value;
            this.Text0 = Text0;
            this.Text = Text;
            this.Text1 = Text1;
            this.Text2 = Text2;
        }
        public ObjetoListItem(bool Checked, string Value, string Text, string AddText, string EditText, string EditNavigateUrl, string DelText, string DelImageUrl)
        {
            this.Checked = Checked;
            this.Value = Value;
            this.Text = Text;
            this.AddText = AddText;
            this.EditText = EditText;
            this.EditNavigateUrl = EditNavigateUrl;
            this.DelText = DelText;
            this.DelImageUrl = DelImageUrl;
        }
        public ObjetoListItem(bool Checked, string Value, string Text0, string Text, string Text1, string Text2, string AddText, string EditText, string EditNavigateUrl, string DelText, string DelImageUrl)
        {
            this.Checked = Checked;
            this.Value = Value;
            this.Text0 = Text0;
            this.Text = Text;
            this.Text1 = Text1;
            this.Text2 = Text2;
            this.AddText = AddText;
            this.EditText = EditText;
            this.EditNavigateUrl = EditNavigateUrl;
            this.DelText = DelText;
            this.DelImageUrl = DelImageUrl;
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            lnkAdd.Command += new System.Web.UI.WebControls.CommandEventHandler(lnkAdd_Command);
            lnkDel.Command += new System.Web.UI.WebControls.CommandEventHandler(lnkDel_Command);
            imgbtnDel.Command += new System.Web.UI.WebControls.CommandEventHandler(lnkDel_Command);
        }
        void lnkAdd_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            lnkAddCommand(sender, e);
        }
        void lnkDel_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            lnkDelCommand(sender, e);
        }
        void imgbtnDel_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            lnkDelCommand(sender, e);
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            RenderContents(writer);
        }
    }
}
